package org.jash.imdemo;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;

public class AddFriendActivity extends AppCompatActivity {
    private EditText name;
    private EditText remark;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_friend);
        name = findViewById(R.id.name);
        remark = findViewById(R.id.remark);
        findViewById(R.id.add).setOnClickListener(v -> {
            new Thread(() -> {
                try {
                    EMClient.getInstance().contactManager().addContact(name.getText().toString(), remark.getText().toString());
                    runOnUiThread(() -> Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show());
                } catch (HyphenateException e) {
                    runOnUiThread(() -> Toast.makeText(this, "添加失败, 原因: " + e.getDescription(), Toast.LENGTH_SHORT).show());
                }
            }).start();
        });

    }
}